﻿using Server.Protocol;
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace ClientTest
{
    class Program
    {
        static void Main(string[] args)
        {
            //var parser = ProtocolParser.GetUTF8Parser();
            //string sendMsg = "你好";
            //byte[] data = parser.Encode(sendMsg);
            //parser.Complete += (x) =>
            //      {
            //          Console.WriteLine(x);
            //      };
            //parser.Push(data, 0, data.Length);


            //for (int i = 0; i < 10; i++)
            //{
            //    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            //    socket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12345));

            //    Console.WriteLine("发送:{0} 10次", sendMsg);
            //    for (int j = 0; j < 10; j++)
            //    {
            //        socket.Send(parser.Encode(sendMsg));
            //    }
            //}

            RPCParser rpc = new RPCParser();

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 12345));

            while (true)
            {
                Console.WriteLine("===>");
                string msg = Console.ReadLine();
                socket.Send(rpc.Encode(msg));
            }

            Console.ReadKey();
        }
    }
}
